#!/usr/bin/env bash

while IFS=$'\t' read -r F B S; do

	IFS=$'\t' read -r PICKUP_NO AK SK <<< $(mysql --defaults-group-suffix=.lk.admin --column-names=false lk_$F -e'select pu.ch_pickup_no, ca.ak, ca.sk from opr_product pd join opr_pickup pu on pd.pickup_id = pu.id join sys_channel_auth ca on ca.channel_id = pu.channel_id where pd.barcode = '\'$B\')

URL="/factory/lake/pickup/${PICKUP_NO}/product/${B}/status"
TIMESTAMP=$(date +%s)
NONCE=$(uuidgen)
SIG=$(echo "POST
${URL,,}
${TIMESTAMP}
${NONCE}" | openssl sha256 -binary -mac HMAC -macopt key:${SK} | base64)

BODY=$(echo '{"state":0,"noWash":false}' | jq -rcM '.pickupNo="'${PICKUP_NO}'" | .barcode="'${B}'" | .status="'${S}'"')
#BODY=$(echo '{"state":0,"noWash":false}' | jq -rcM '.pickupNo="'${PICKUP_NO}'" | .barcode="'${B}'" | .status="'${S}'"')
echo $BODY


curl -v -H'Authorization: ROC-HmacSHA256-1.0 '${AK},${TIMESTAMP},${NONCE},${SIG} -H'Content-Type: application/json' -d$BODY https://partner.dajingxiapp.com$URL

done < ~/Downloads/shipped_hzqy.csv
